Skip to content

Add NotImplementedType.__bool__ with its DeprecationWarning - #1349

Open
jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:fix/notimplemented-bool
Open

jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:fix/notimplemented-bool

Conversation

@jseop-lim

Copy link
Copy Markdown
Contributor

Description

Part of #1291 (item 4).

NotImplementedBuiltins defines no nb_bool slot, so dir(NotImplemented) lacks __bool__ and bool(NotImplemented) is true without a warning. CPython 3.9 to 3.13 define notimplemented_bool, which emits a DeprecationWarning and returns true.

AS-IS

>>> '__bool__' in dir(NotImplemented)
False
>>> import warnings; warnings.simplefilter('error')
>>> bool(NotImplemented)
True

TO-BE

>>> '__bool__' in dir(NotImplemented)
True
>>> bool(NotImplemented)
DeprecationWarning: NotImplemented should not be used in a boolean context

(matching CPython)

Changes

  • Add an nb_bool slot to NotImplementedBuiltins that warns and returns true, and the message to ErrorMessages.
  • Add a test to tests/test_object.py.

Testing

mx python-jvm on darwin-aarch64, then mx graalpytest on test_object.py (the new test fails on the unpatched build and passes with the fix) and the tagged test_bool (31 passed). mx python-checkcopyrights, mx eclipseformat and mx checkstyle are clean.

NotImplementedType had no nb_bool slot, so dir(NotImplemented) lacked
__bool__ and bool(NotImplemented) was true without the
DeprecationWarning that CPython 3.9 to 3.13 emit.

Signed-off-by: Jeongseop Lim <jeongseop_lim@korea.ac.kr>
@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant